import React from 'react'

import {
  Route,
  hashHistory,
  IndexRoute,
} from 'react-router'

import App from './containers/App'
import Login from './containers/App/login'
import Welcome from './pages/welcome'



/*勤务管理 开始*/
import {
  police,
} from './pages/serviceManagement/police'

import {
  task,
} from './pages/serviceManagement/task'

import {
  work,
} from './pages/serviceManagement/work'

import {
  qrcode,
} from './pages/serviceManagement/qrcode'

import {
  declare,
} from './pages/serviceManagement/declare'

import {
  file,
} from './pages/serviceManagement/file'

import {
  household,
} from './pages/serviceManagement/household'
/*勤务管理 结束*/

/*基础信息 开始*/
import {
  house,
} from './pages/baseInfo/house'

import houseDetail from './pages/baseInfo/house/building/houseDetail'

import roomDetail from './pages/baseInfo/house/building/roomDetail'

import {
  pop,
} from './pages/baseInfo/pop'

import {
  group,
} from './pages/baseInfo/group'

import {
  security,
} from './pages/baseInfo/security'

import {
  cue,
} from './pages/baseInfo/cue'

import {
  goods,
} from './pages/baseInfo/goods'

import {
  count,
} from './pages/baseInfo/count'
/*基础信息 结束*/

/*基础应用 开始*/
import {
  apphouse,
} from './pages/appBase/apphouse'

import {
  apppop,
} from './pages/appBase/apppop'


import {
  userManage,
} from './pages/manage'


/*进入路由的判断*/
window.loginFlag = true
function isLogin(){
  const token = sessionStorage.getItem('token')
  console.log(token)
  if(!token){
    hashHistory.push('/login')
  } else {
    if(loginFlag == true){
      // hashHistory.push('/')
    }
    loginFlag = false
  }
}

const routes = (
  <Route>
    <Route path="/" component={App} onEnter={isLogin}>
      <IndexRoute component={Welcome}/>

      {/***勤务管理 开始*/}
      <Route path="/police" component={police} />
      <Route path="/task" component={task} />
      <Route path="/work" component={work} />
      <Route path="/qrcode" component={qrcode} />
      <Route path="/declare" component={declare} />
      <Route path="/file" component={file} />
      <Route path="/household" component={household} />
      {/***勤务管理 结束*/}

      {/***基础信息 开始*/}
      <Route path="/house" component={house} />
        <Route path="/houseDetail/:houseId" component={houseDetail} />
          <Route path="/roomDetail/:houseId/:roomId" component={roomDetail} />

      <Route path="/pop" component={pop} />
      <Route path="/group" component={group} />
      <Route path="/security" component={security} />
      <Route path="/cue" component={cue} />
      <Route path="/goods" component={goods} />
      <Route path="/count" component={count} />
      {/***基础信息 结束*/}

      {/***基础应用 开始*/}
      <Route path="/apphouse" component={apphouse} />
      <Route path="/apppop" component={apppop} />
      {/***基础应用 结束*/}

      <Route path="/userManage" component={userManage} />

    </Route>

    <Route path="/login" component={Login} />
  </Route>
);

export default routes;
